class LoginController < ApplicationController
  
  def user_verify
    reader = Reader.new(params[:reader])
    
    if(reader=reader.try_login)
      #      从flash中取出用户登录前要到达的页面.登录成功后转到该页面
      session[:user] = reader
      pre_request = flash[:request]
      if(pre_request)
        redirect_to url_for(flash[:request])
      elsif
        redirect_to :controller => 'out',:action => 'index'
      end
      
    elsif
      flash[:notice] = '登录失败!'
      redirect_to :action => 'login'
    end
  end
  
  def login
    
    #  由于flash只能传递一次请求, 所以中间的action需要用flash.keep()保存住这个值
#    flash.keep(:request)
    render :layout => false 
  end
  
  def logout
    session[:user] = nil
    redirect_to :controller => 'login',:action => 'login'
  end
  
end
